
const path_pre = "/pages"
const index_page = path_pre + "/index/index"
const add_house_page = path_pre +"/add-house/add-house"
const book_detail_page = path_pre +"/book-detail/book-detail"
const add_book_page = path_pre +"/add-book/add-book"
const bill_detail_page = path_pre + "/bill-detail/bill-detail"
const record_page = path_pre + "/record/record"
const edit_book_page = path_pre + "/edit-book/edit-book"
const account_page = path_pre + "/account/account"
const get_cash_page = path_pre + "/get-cash/get-cash"
const cash_detail_page = path_pre + "/cash-detail/cash-detail"
const cash_record_page = path_pre + "/cash-record/cash-record"
const advice_page = path_pre + "/advice/advice"
// ,
//   "pages/book-detail/book-detail",
//   "pages/add-book/add-book",

//   "pages/test/test",
//   ,
//   "pages/logs/logs"


function backToIndexPage() {
  wx.switchTab({
    url: index_page,
  })

}

function toAddBookPage(data) {
  if(data){
    data = JSON.stringify(data)
    wx.navigateTo({
      url: add_book_page+"?data="+data
    })
  }
  
}

function toAddHousePage() {
  wx.navigateTo({
    url: add_house_page
  })
}

function toBookDeatilPage(data) {
  if (data) {
    data = JSON.stringify(data)
    wx.navigateTo({
      url: book_detail_page + "?data=" + data
    })
  } 
}


function toBillDeatilPage(data) {
  if (data) {
    data = JSON.stringify(data)
    wx.navigateTo({
      url: bill_detail_page + "?data=" + data
    })
  }
}

function toRecordPage() {
  wx.navigateTo({
    url: record_page
  })
}

function toEditBookPage(data) {

  if (data) {
    data = JSON.stringify(data)
    wx.navigateTo({
      url: edit_book_page + "?data=" + data
    })
  }
  
}

function toAccountPage() {
  wx.navigateTo({
    url: account_page
  })
}

function toGetCashPage(data) {

  if (data) {
    data = JSON.stringify(data)
    wx.navigateTo({
      url: get_cash_page + "?data=" + data
    })
  }
  
}

function toCashDeatilPage(data) {
  if (data) {
    data = JSON.stringify(data)
    wx.navigateTo({
      url: cash_detail_page + "?data=" + data
    })
  }
}

function toCashRecordPage() {
  wx.navigateTo({
    url: cash_record_page
  })
}

function toAdvicePage() {
  wx.navigateTo({
    url: advice_page
  })
}


function successBackPage(msg, duration){
  wx.showToast({
    title: msg||"操作成功",
    icon: 'success',
    duration: duration||500
  })

  setTimeout(function () {
    wx.navigateBack({
      delta: 1
    })
  }, duration || 500)
}

module.exports = {
  toAddHousePage, toAddBookPage, toBookDeatilPage, toBillDeatilPage, toRecordPage, toEditBookPage, toAccountPage, toGetCashPage, toCashDeatilPage, toCashRecordPage, toAdvicePage, successBackPage
}